package com.csmz.mybookreadernew.UI.Fragment.MyReader;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.ListView;

import com.blankj.utilcode.util.SPUtils;
import com.csmz.mybookreadernew.Adapter.ListViewAdapter;
import com.csmz.mybookreadernew.R;
import com.csmz.mybookreadernew.RssUtils.RssFeed;
import com.csmz.mybookreadernew.RssUtils.RssItem;
import com.csmz.mybookreadernew.UI.Activity.WebViewActivity;
import com.king.base.BaseFragment;

public class MyNewsReadFragment_05 extends BaseFragment implements AdapterView.OnItemClickListener {
    private ListView itemList;
    private static RssFeed feed = null;
    private static Context context;
    public static void getRssFeed(Context c,RssFeed f){
        feed=f;
        context=c;
    }

    @Override
    public int inflaterRootView() {
        return R.layout.fragment_my_news;
    }

    @Override
    public void initUI() {
        showListView();
    }

    /*
     * 把RSS内容绑定到ui界面进行显示
     */
    private void showListView() {
        itemList=findView(R.id.list);
        if (feed == null) {
            setFeedData();
        }else {
            ListViewAdapter adapter=new ListViewAdapter(getActivity(),feed);
            itemList.setAdapter(adapter);
            itemList.setOnItemClickListener(this);
            itemList.setSelection(0);
        }
    }

    private void setFeedData() {
        feed=new RssFeed();
        RssItem item01=new RssItem("2月CPI涨幅创10个月新高 全年通胀压力大仍可控", "2013-03-11 09:19:40", "http://finance.qq.com/a/20130311/002347.htm");
        feed.addItem(item01);
        RssItem item02=new RssItem("郎咸平：民营企业应知所进退 藏富于民是真谛","2012-07-01 23:05:06","http://finance.qq.com/a/20120701/000970.htm");
        feed.addItem(item02);
        RssItem item03=new RssItem("外媒称香港回归15年打破“经济将死”预言","2012-07-01 17:34:12","http://finance.qq.com/a/20120701/000868.htm");
        feed.addItem(item03);
        RssItem item04=new RssItem("全球城市人员风险指数发布 中国居中游","2012-06-01 12:40:00","http://finance.qq.com/a/20120601/006102.htm");
        feed.addItem(item04);
        RssItem item05=new RssItem("香港中国商会陈经纬：海外投资仍处于初级阶段","2012-05-29 13:32:19","http://finance.qq.com/a/20120529/005072.htm");
        feed.addItem(item05);
        RssItem item06=new RssItem("住建部回应自来水合格率50% 称供水总体安全","2012-05-12 21:56:44","http://finance.qq.com/a/20120512/016931.htm");
        feed.addItem(item06);
        RssItem item07=new RssItem("人民币兑美元累计升值达3成 接近均衡汇率水平","2012-04-23 11:34:39","http://finance.qq.com/a/20120423/005131.htm");
        feed.addItem(item07);
        RssItem item08=new RssItem("中国经济高速增长趋缓 无碍实现全年预期目标","2012-04-21 20:39:02","http://finance.qq.com/a/20120421/002590.htm");
        feed.addItem(item08);
        RssItem item09=new RssItem("2月CPI涨幅创10个月新高 全年通胀压力大仍可控111","2013-03-11 09:19:40","http://finance.qq.com/a/20130311/002347.htm");
        feed.addItem(item09);
        RssItem item10=new RssItem("实德指媒体窃公司机密 已向某媒体递律师函","2012-04-21 19:32:04","http://finance.qq.com/a/20120421/002569.htm");
        feed.addItem(item10);
        RssItem item11=new RssItem("3月份广东宏观经济出现“触底回稳”迹象","2012-04-21 16:29:30","http://finance.qq.com/a/20120421/002466.htm");
        feed.addItem(item11);
        ListViewAdapter adapter=new ListViewAdapter(getActivity(),feed);
        itemList.setAdapter(adapter);
        itemList.setOnItemClickListener(this);
        itemList.setSelection(0);
    }

    @Override
    public void initData() {

    }

    @Override
    public void addListeners() {

    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        SPUtils.getInstance("Url").put("link",feed.getItem(position).getLink());
        startActivity(new Intent(getActivity(),WebViewActivity.class));
    }
}
